#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
    import elsLibs.ShotInfoFromFile as elssif
    reload(elssif)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckELSMovieExists(CheckBase):
    def __init__(self):
        super(CheckELSMovieExists, self).__init__()
        pass

    def init_file(self):
        scene_name = mu.sceneName()
        sif = elssif.ShotInfoFromFile(scene_name)
        self.seqshot = sif.get_seqshot

    def check(self):
        current_file = mu.sceneName()
        if not current_file:
            result_log = u'Error: 当前文件未保存!'
            return result_log
        if current_file.startswith('els_'):
            result_log = u'Error: 当前文件非els项目镜头规则!'
            return result_log
        try:
            self.init_file()
        except:
            result_log = u'Error:当前文件不符合ELS项目资产文件命名规则'
            return result_log

        mov_file = current_file[0:-3] + '.mov'
        tpose_mov_file = current_file[0:-3] + '_tpose.mov'
        add5_mov_file = current_file[0:-3] + '_add5.mov'

        result_log = 'Succeed:'
        if os.path.exists(mov_file):
            result_log += u'<br><font color=\"#007900\">存在:%s' % os.path.basename(mov_file)
        else:
            result_log +=  u'<br><font color=\"#FF0000\">不存在:%s</font>' % os.path.basename(mov_file)
        if os.path.exists(tpose_mov_file):
            result_log += u'<br><font color=\"#007900\">存在:%s' % os.path.basename(tpose_mov_file)
        else:
            result_log += u'<br><font color=\"#FF0000\">不存在:%s</font>' % os.path.basename(tpose_mov_file)
        if os.path.exists(add5_mov_file):
            result_log += u'<br><font color=\"#007900\">存在:%s' % os.path.basename(add5_mov_file)
        else:
            result_log += u'<br><font color=\"#FF0000\">不存在:%s</font>' % os.path.basename(add5_mov_file)
        if u'不存在' in result_log:
            result_log = result_log.replace('Succeed:', 'Warning:')
        return result_log

    def fix(self):
        pass